<template>   
<div >
      
 
       <div class="bo">
    <div class="container">

      <h1 id="he">To Register</h1>
      
        <div class="form-control">
          <input type="text" required v-model="username">
          <label>
            <span style="transition-delay: 0ms">请</span>
              <span style="transition-delay: 50ms">输</span>
              <span style="transition-delay: 180ms">入</span>
            <span style="transition-delay: 150ms">用</span>
              <span style="transition-delay: 20ms">户</span>
              <span style="transition-delay: 100ms">名</span>
             
        </label> 
        </div>

        <div class="form-control">
          <input type="password" required v-model="password">
          <label>
            <span style="transition-delay: 0ms">请</span>
              <span style="transition-delay: 50ms">输</span>
              <span style="transition-delay: 180ms">入</span>
            <span style="transition-delay: 150ms">密</span>
              <span style="transition-delay: 20ms">码</span>
          </label>
        </div>
        <div class="form-control">
          <input type="password" required v-model="confirmedpassword">
          <label>
            <span style="transition-delay: 0ms">请</span>
              <span style="transition-delay: 50ms">确</span>
              <span style="transition-delay: 180ms">认</span>
            <span style="transition-delay: 150ms">密</span>
              <span style="transition-delay: 20ms">码</span>
          </label>
        </div>

        <button class="btn" @click="toRegist()" >Register</button>

        <p class="text">Already have an account? <a id="a" href="/#/">Log</a> </p>
      
    </div>
    </div>

</div>
</template>


<script>

    export default {
        data () {
            return {
              username:'',
              password:'',
              confirmedpassword:''
            }
        },
        methods: {
            toRegist(){
                this.axios({
                    method: 'post',
                    url: '/manage/register',
                    data: {
                        userName: this.username,
                        userPassword: this.password,
                        confirmedPassword: this.confirmedpassword,
                    }
                    })
                    .then(res=>{                    //请求成功后执行函数
                        if(res.data.error_massage === "success"){
                            this.$message({
                                type: 'success',
                                message: '注册成功!请登录'
                            });
                            this.$router.push({name: 'log'}) 	//登录验证成功路由实现跳转

                            console.log("登录成功")
                        }else{
                            this.$message({
                                type: 'error',
                                message: res.data.error_massage+"!"
                            });
                            console.log("登录失败")
                        }
                    }).catch(err=>{                   //请求错误后执行函
                    console.log("请求错误")
                    })  

                //this.$router.push({name: 'log'}) 
            } 

        },
        beforeCreate () {
          document.querySelector('body').setAttribute('style', 'background:#ffffff;')
        },
        beforeDestroy () {
        document.querySelector('body').removeAttribute('style')
        }
    }
</script>
<style scoped>
    
    @import url('https://fonts.googleapis.com/css?family=Muli&display=swap');

* {
  box-sizing: border-box;
}

.bo {
  background-image:url('../assets/bg.jpg');
  background-size: 100%;
  color: #fff;
  font-family: 'Muli', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: hidden;
  margin: 0;
}

.container {
  background-color: rgba(0, 0, 0, 0.4);
  padding: 20px 40px;
  border-radius: 5px;
}

.container h1 {
  text-align: center;
  margin-bottom: 30px;
}

.container a {
  text-decoration: none;
  color: lightblue;
}

.btn {
  cursor: pointer;
  display: inline-block;
  width: 100%;
  background: lightblue;
  padding: 15px;
  font-family: inherit;
  font-size: 16px;
  border: 0;
  border-radius: 5px;
}

.btn:hover {
  outline: 0;
  transform: scale(1.02);
}

.btn:active {
  transform: scale(0.98);
}

.text {
  margin-top: 30px;
}

#a:hover {
  transform: scale(1.05);
}

.form-control {
  position: relative;
  margin: 20px 0 40px;
  width: 300px;
}

.form-control input {
  background-color: transparent;
  border: 0;
  border-bottom: 2px #fff solid;
  display: block;
  width: 100%;
  padding: 15px 0;
  font-size: 18px;
  color: #fff;
}

.form-control input:focus,
.form-control input:valid {
  outline: 0;
  border-bottom-color: lightblue;
}

.form-control label {
  position: absolute;
  top: 15px;
  left: 0;
  pointer-events: none;
}

.form-control label span {
  display: inline-block;
  font-size: 18px;
  min-width: 5px;
  transition: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.form-control input:focus + label span,
.form-control input:valid + label span {
  color: lightblue;
  transform: translateY(-30px);
}
    
  </style>